package org.example.mallchat.common.thread;

import org.example.mallchat.common.domain.local.RequestInfo;
import org.springframework.stereotype.Component;

/**
 * @author: zzh
 * @date: 2024/12/22 22:14:14
 * @version: 1.0
 */
@Component// 存储当前线程的变量
public class ThreadLocalHandler {
    private static final ThreadLocal<RequestInfo> threadLocal = new ThreadLocal<>();

    public static void setRequestInfo(RequestInfo requestInfo) {
        threadLocal.set(requestInfo);
    }
    public static RequestInfo getRequestInfo() {
        return threadLocal.get();
    }

    // 清除当前线程的变量!
    public static void remove() {
        threadLocal.remove();
    }

}
